﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AutoServey
{
    public class ProcessMethods
    {
        static string WinrarPath = @"F:\winrar\WinRAR.exe";

        public void zipFile(string filePath, string zipPath)
        {
            string zipStr = string.Format(@"{2} a -ep1 {0} {1} &exit", zipPath, filePath,WinrarPath);
            runProcess(zipStr);
        }

        public void unzipFile(string filePath, string zipPath)
        {
            string unzipStr = string.Format(@"{2} X -r -y {0} {1} &exit", zipPath, filePath,WinrarPath);
            runProcess(unzipStr);
        }

        public void runProcess(string processStr)
        {
            System.Diagnostics.Process compressP = new System.Diagnostics.Process();
            compressP.StartInfo.FileName = "cmd.exe";
            compressP.StartInfo.UseShellExecute = false;    //是否使用操作系统shell启动
            compressP.StartInfo.RedirectStandardInput = true;//接受来自调用程序的输入信息
            compressP.StartInfo.RedirectStandardOutput = true;//由调用程序获取输出信息
            compressP.StartInfo.RedirectStandardError = true;//重定向标准错误输出
            compressP.StartInfo.CreateNoWindow = false;//不显示程序窗口
            compressP.Start();//启动程序
            compressP.StandardInput.WriteLine(processStr);
            compressP.WaitForExit();//等待程序执行完退出进程
            compressP.Close();
        }
    }
}
